package com.qf.serevice.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.MedicineInfo;
import com.qf.mapper.MedicineInfoMapper;
import com.qf.pojo.BaseResult;
import com.qf.serevice.MedicineInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MedicineInfoServiceImpl implements MedicineInfoService {
    BaseResult baseResult = new BaseResult();
    @Resource
    MedicineInfoMapper medicineInfoMapper;
    //查询全部药品信息
    @Override
    public BaseResult findAllMedicineInfo(Integer page,Integer size,String name) {
        PageHelper.startPage(page,size);
        String ypname = "%"+name+"%";
        List<MedicineInfo> medicineInfoList = medicineInfoMapper.findAllMedicineInfo(ypname);
        System.out.println(medicineInfoList);
        if (medicineInfoList!=null){
            PageInfo<MedicineInfo> of = PageInfo.of(medicineInfoList);
            baseResult.setCode(1);
            baseResult.setInfo("数据查询成功");
            baseResult.setData(of.getList());
            baseResult.setTotal(of.getTotal());
            return baseResult;
        }else {
            baseResult.setInfo("查询数据有误！");
            return baseResult;
        }
    }
}
